package my1024.controller;

import java.awt.KeyEventDispatcher;
import java.awt.event.KeyEvent;

/**
 * minhvv, p18, IFI, TPE 01/2014 - 07/2014
 */

public class InputProcessing implements KeyEventDispatcher {
	private LogicController controller;

	public InputProcessing(LogicController controller) {
		this.controller = controller;
	}

	@Override
	public boolean dispatchKeyEvent(KeyEvent e) {
		if (e.getID() == KeyEvent.KEY_PRESSED) {
			processKeyPressed(e);
		}
		// else if (e.getID() == KeyEvent.KEY_RELEASED) {
		// } else if (e.getID() == KeyEvent.KEY_TYPED) {
		// }
		return false;
	}

	public void processKeyPressed(KeyEvent e) {
		int keyCode = e.getKeyCode();

		switch (keyCode) {
		case KeyEvent.VK_LEFT:
		case KeyEvent.VK_RIGHT:
		case KeyEvent.VK_UP:
		case KeyEvent.VK_DOWN:
			controller.processLogic(keyCode);
			break;
		case KeyEvent.VK_R:
			controller.processResetRotate();
			break;
		case KeyEvent.VK_SPACE:
			controller.startGame();
			break;
		default:
			break;
		}
	}
}
